var json = {
	"name": "里根号",
	"value": "",
	"list": [{
		"name": "作战能力",
		"value": "",
		"list": [{
			"name": "侦查与预警能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "攻击能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "防御能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "机动能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "通信能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "自持能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "补给能力",
			"from": "",
			"remark": "",
			"list": []
		}, {
			"name": "协同能力",
			"from": "",
			"remark": "",
			"list": []
		}]
	}, {
		"name": "作战行动",
		"from": "",
		"remark": "",
		"list": []
	}, {
		"name": "隶属部队",
		"from": "",
		"remark": "",
		"list": []
	}, {
		"name": "部队编成",
		"from": "",
		"remark": "",
		"list": []
	}, {
		"name": "武器装备",
		"from": "",
		"remark": "",
		"list": []
	}, {
		"name": "战备训练",
		"from": "",
		"remark": "",
		"list": []

	}]
};


var echarts_data = [];
var echarts_lins = [];
var globalSeriesData = []; //定义的全局数组变量
var categorie_index = 0;//种类级别_index 标识

// var colors = ['#c23531', '#2f4554', '#04f2a7', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
var colors = ['#f1462c', '#ffca00', '#2d88f1', '#1dc9cd', '#54df6c', '#2aa146', '#fe4f60', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
var sizes = [50, 40, 30, 20, 10];

function initData() {
	digui(json);
	categorie_index = 0;
}


function getItemData(itemName, categorie) {
	var obj = getColorAndSizeByCategories(categorie);
	return {
		name: itemName,
		symbolSize: obj.size,
		draggable: true,
		category: categorie,
		itemStyle: {
			borderColor: obj.color,
			borderWidth: 2,
			shadowBlur: 10,
			shadowColor: obj.color,
			color: '#001c43',

		}
	};
}

function getItemLine(source, target, value) {
	return {
		source: source,
		target: target,
		// value: value,
		lineStyle: {
			normal: {
				color: {
					type: 'linear',
					x: 0,
					y: 0,
					x2: 0,
					y2: 1,
					colorStops: [{
						offset: 0,
						color: '#e0f55a' // 0% 处的颜色
					}, {
						offset: 1,
						color: '#639564' // 100% 处的颜色
					}]
				}
			}
		}
	};
}
function digui(data) {
	echarts_data.push(getItemData(data.name, categorie_index));
	if (data.list.length > 0) {
		categorie_index++;
		initLine(data.name, data.list);
		data.list.forEach(function (item, index) {
			digui(item);
		});
	}
}

function initLine(data, list) {
	list.forEach(function (item, index) {
		echarts_lins.push(getItemLine(data, item.name, "属性"));
	});
}

/**
 * 根据级别 返回对应的颜色值
 */
function getColorAndSizeByCategories(number) {
	var obj = {};
	if (number > 4) {
		number = 4;
	}
	switch (number) {
		case 0:
			obj.color = colors[0];
			obj.size = sizes[0];
			break;
		case 1:
			obj.color = colors[1];
			obj.size = sizes[1];
			break;
		case 2:
			obj.color = colors[2];
			obj.size = sizes[2];
			break;
		case 3:
			obj.color = colors[3];
			obj.size = sizes[3];
			break;
		case 4:
			obj.color = colors[4];
			obj.size = sizes[4];
			break;
	}
	return obj;
}

//var color = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
//这部分模拟数据库传来的数据，只是无法交互更新
var categories = [{
	name: 0,

}, {
	name: 1,

}, {
	name: 2,

}, {
	name: 3,

}, {
	name: 4,

}, {
	name: 5,

}]
var graph = {
	data: echarts_data,
	links: echarts_lins
}

var optionFromDB = {
	backgroundColor: '#1a4377',

	series: [{
		draggable: true,
		animation: false,//闪一下的动画 必须加
		zoom: 2,//固定 x y 的时候 zoom不能放大 
		type: 'graph',
		layout: 'force',
		roam: true,
		// edgeSymbol: ['circle', 'arrow'],//箭头
		label: {
			show: true,
			position: 'bottom',
			formatter: '{b}',
			textStyle: { //标签的字体样式
				color: '#cde6c7', //字体颜色
				fontStyle: 'normal',//文字字体的风格 'normal'标准 'italic'斜体 'oblique' 倾斜
				// fontWeight : 'bolder',/ /'normal'标准'bold'粗的'bolder'更粗的'lighter'更细的或100 | 200 | 300 | 400...
				// fontFamily : 'sans-serif',//文字的字体系列
				fontSize: 12, //字体大小
			}
		},
		force: {
			repulsion: 140,
			layoutAnimation: true,//是否开启动画
		},
		data: graph.data,
		links: graph.links,
		categories: categories,
		//   type: 'graph',      
		//   layout: 'force',
		//  symbolSize: 34,
		//   animationDurationUpdate: 750

	}]
}